package grex.genes;

import grex.Prediction;
import grex.PredictionContainer;

public class Greater extends Gene implements IContinuousOperator{
  private static final int NROFCILDREN = 2;
 
  public Greater() {
    super(NROFCILDREN);
  }

  public synchronized void execute(Gene parent,PredictionContainer data,int mode) throws GeneException {
      this.parent = parent;
    
      Gene[] childs =  this.getChildren();
   /* PredictionContainer lResult = data;
    PredictionContainer rResult = data.clone();
    childs[0].execute(this, lResult, mode);
    childs[1].execute(this, rResult, mode);
        for(double[] key : data.keySet()) {
            if (lResult.get(key).getPrediction() > rResult.get(key).getPrediction()) {
                data.get(key).setPrediction(1);
            } else {
                data.get(key).setPrediction(0);
            }
        }//*/
      
      for(Prediction prediction:data.values()){
        if(((IOperatorTerminal)childs[0]).execute(this, prediction) > ((IOperatorTerminal)childs[1]).execute(this, prediction))
            prediction.setCondition(true);
           else 
            prediction.setCondition(false);
      }//*/
        
  }
  
  public Object clone() {
    Greater newGreater = new Greater();
    newGreater.setOptions(ops);
    cloneChildren(newGreater);
 //   newGreater.setParent(parent);
     return newGreater;
  }
  public String toString() {
    return ">";
  }
  public boolean equals(Object o){
        if(o instanceof Greater){
            Greater g =(Greater) o;
            if(getChildren()[0].equals(g.getChildren()[0]) || getChildren()[0].equals(g.getChildren()[1]))
                if(getChildren()[1].equals(g.getChildren()[0]) || getChildren()[1].equals(g.getChildren()[1]))
                    return true;
        }
        return false;
    }

}
